package cn.dulian.fruit.servlets;

import cn.dulian.fruit.dao.FruitDAO;
import cn.dulian.fruit.dao.impl.FruitDAOImpl;
import cn.dulian.fruit.pojo.Fruit;
import cn.dulian.myssm.myspringmvc.ViewBaseServlet;
import cn.dulian.myssm.myspringmvc.util.StringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author dulian
 * @create 2022-04-07 20:32
 */
@WebServlet("/update.do")
public class UpdataServlet extends ViewBaseServlet {
    private FruitDAO fruitDAO = new FruitDAOImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.设置编码
        req.setCharacterEncoding("UTF-8");
        //2.获取值
        String fidStr = req.getParameter("fid");
        int fid = Integer.parseInt(fidStr);
        String fname = req.getParameter("fname");
        String priceStr = req.getParameter("price");
        int price = Integer.parseInt(priceStr);
        String fcountStr = req.getParameter("fcount");
        int fcount = Integer.parseInt(fcountStr);
        String remark = req.getParameter("remark");

        Fruit fruit = new Fruit(fid,fname,price,fcount,remark);
        fruitDAO.UpdateFruit(fruit);

        //也是要重定向，因为要让index重新申请数据
        resp.sendRedirect("index");




    }
}
